package com.nwpu.coursesupport.entity.bean;


import lombok.Data;


@Data
public class Response<T> {

//    @ApiModelProperty(name = "code",value = "响应状态码,0为成功，其他为失败")
    private Integer code;

//    @ApiModelProperty(name = "msg",value = "提示消息")
    private String msg;

//    @ApiModelProperty(name = "data",value = "响应数据")
    private T data;

    public Response(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Response() {
    }

    public Response(T data) {
        this.data = data;
    }

    public static<T> Response<T> ok(T data){
        Response<T> response = new Response<T>(data);
        response.setCode(0);//操作成功
        response.setMsg("success");
        return response;
    }

    public static<T> Response<T> fail(String msg){
        Response<T> response = new Response<T>();
        response.setCode(1);//操作失败
        response.setMsg(msg);
        return response;
    }

    public Response<T> msg(String msg){
        this.setMsg(msg);
        return this;
    }

    public Response<T> code(Integer code){
        this.setCode(code);
        return this;
    }


}
